{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.datasets import load_svmlight_file\n",
    "import json\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train, y_train = load_svmlight_file(\"data/train_dev_test/train_demo.txt\")\n",
    "mat = X_train.todense()\n",
    "\n",
    "\n",
    "# 读取各列名称\n",
    "with open(\"data/train_dev_test/keys.json\", \"r\", encoding=\"utf-8\") as f1:\n",
    "    header = json.load(f1)[\"_feature\"]\n",
    "header = [k for k,v in header.items() if v>=0]\n",
    "len(header)\n",
    "\n",
    "\n",
    "df1 = pd.DataFrame(mat)\n",
    "df1.columns = header\n",
    "\n",
    "df2 = pd.DataFrame(y_train).astype(int)\n",
    "df2.columns = ['target']\n",
    "\n",
    "df = pd.concat([df2, df1], axis=1) ## 第一列为target\n",
    "del df1, df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>target</th>\n",
       "      <th>third_id</th>\n",
       "      <th>orderid</th>\n",
       "      <th>entry</th>\n",
       "      <th>order_invoice_type</th>\n",
       "      <th>stock</th>\n",
       "      <th>order_type</th>\n",
       "      <th>order_state</th>\n",
       "      <th>oi_orderType</th>\n",
       "      <th>oi_idShipmentType</th>\n",
       "      <th>...</th>\n",
       "      <th>rcin_summaryPredictResults_填写发票信息</th>\n",
       "      <th>rcin_summaryPredictResults_企业用户</th>\n",
       "      <th>rcin_summaryPredictResults_微信订单查询</th>\n",
       "      <th>rcin_summaryPredictResults_电子书</th>\n",
       "      <th>rcin_summaryPredictResults_无法加入购物车</th>\n",
       "      <th>rcin_summaryPredictResults_加盟快递</th>\n",
       "      <th>rcin_summaryPredictResults_商品好评率</th>\n",
       "      <th>rcin_summaryPredictResults_参加夺宝岛</th>\n",
       "      <th>rcin_summaryPredictResults_网银钱包提现异常</th>\n",
       "      <th>rcin_summaryPredictResults_补差价</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>22</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5</td>\n",
       "      <td>6964.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>21</td>\n",
       "      <td>798.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>35</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>22.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>22</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>22.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 1099 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   target  third_id  orderid  entry  order_invoice_type  stock  order_type  \\\n",
       "0      22       0.0      1.0    3.0                 2.0    0.0        13.0   \n",
       "1       5    6964.0      1.0    1.0                 1.0    2.0         1.0   \n",
       "2      21     798.0      1.0    1.0                 1.0    2.0         1.0   \n",
       "3      35       0.0      1.0    2.0                 2.0    0.0         3.0   \n",
       "4      22       0.0      1.0    2.0                 2.0    0.0         3.0   \n",
       "\n",
       "   order_state  oi_orderType  oi_idShipmentType  ...  \\\n",
       "0          2.0          15.0               70.0  ...   \n",
       "1          6.0           0.0               70.0  ...   \n",
       "2          2.0           0.0               70.0  ...   \n",
       "3          4.0          22.0               70.0  ...   \n",
       "4          9.0          22.0               70.0  ...   \n",
       "\n",
       "   rcin_summaryPredictResults_填写发票信息  rcin_summaryPredictResults_企业用户  \\\n",
       "0                                0.0                              0.0   \n",
       "1                                0.0                              0.0   \n",
       "2                                0.0                              0.0   \n",
       "3                                0.0                              0.0   \n",
       "4                                0.0                              0.0   \n",
       "\n",
       "   rcin_summaryPredictResults_微信订单查询  rcin_summaryPredictResults_电子书  \\\n",
       "0                                0.0                             0.0   \n",
       "1                                0.0                             0.0   \n",
       "2                                0.0                             0.0   \n",
       "3                                0.0                             0.0   \n",
       "4                                0.0                             0.0   \n",
       "\n",
       "   rcin_summaryPredictResults_无法加入购物车  rcin_summaryPredictResults_加盟快递  \\\n",
       "0                                 0.0                              0.0   \n",
       "1                                 0.0                              0.0   \n",
       "2                                 0.0                              0.0   \n",
       "3                                 0.0                              0.0   \n",
       "4                                 0.0                              0.0   \n",
       "\n",
       "   rcin_summaryPredictResults_商品好评率  rcin_summaryPredictResults_参加夺宝岛  \\\n",
       "0                               0.0                               0.0   \n",
       "1                               0.0                               0.0   \n",
       "2                               0.0                               0.0   \n",
       "3                               0.0                               0.0   \n",
       "4                               0.0                               0.0   \n",
       "\n",
       "   rcin_summaryPredictResults_网银钱包提现异常  rcin_summaryPredictResults_补差价  \n",
       "0                                  0.0                             0.0  \n",
       "1                                  0.0                             0.0  \n",
       "2                                  0.0                             0.0  \n",
       "3                                  0.0                             0.0  \n",
       "4                                  0.0                             0.0  \n",
       "\n",
       "[5 rows x 1099 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 3886 entries, 0 to 3885\n",
      "Columns: 1099 entries, target to rcin_summaryPredictResults_补差价\n",
      "dtypes: float64(1098), int32(1)\n",
      "memory usage: 32.6 MB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       22\n",
       "1        5\n",
       "2       21\n",
       "3       35\n",
       "4       22\n",
       "        ..\n",
       "3881     5\n",
       "3882     8\n",
       "3883    12\n",
       "3884     1\n",
       "3885    11\n",
       "Name: target, Length: 3886, dtype: int32"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"target\"]"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "repeat_pd = pd.DataFrame()\n",
    "for index, row in tqdm(df.iterrows()):\n",
    "    tmp_repeat = pd.DataFrame([row]*121)\n",
    "    tmp_repeat['candicate'] = list(range(1, 122))\n",
    "    tmp_repeat[\"target\"] = tmp_repeat[\"target\"].astype(int)\n",
    "    tmp_repeat[\"target\"] = (tmp_repeat[\"candicate\"] == tmp_repeat[\"target\"]).astype(int)\n",
    "#     repeat_pd = pd.concat([repeat_pd, tmp_repeat], ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from multiprocessing import Pool\n",
    "\n",
    "def _foo(idx):\n",
    "    row = df.loc[idx]    \n",
    "    tmp_repeat = pd.DataFrame([row]*121)\n",
    "    tmp_repeat['candicate'] = list(range(1, 122))\n",
    "    tmp_repeat[\"target\"] = tmp_repeat[\"target\"].astype(int)\n",
    "    tmp_repeat[\"target\"] = (tmp_repeat[\"candicate\"] == tmp_repeat[\"target\"]).astype(int)\n",
    "    return tmp_repeat\n",
    "\n",
    "all_datas = []\n",
    "with Pool(processes=8) as p:\n",
    "    with tqdm(total=df.shape[0]) as pbar:\n",
    "        for i, rp in enumerate(p.imap_unordered(_foo, range(df.shape[0]))):\n",
    "            pbar.update()\n",
    "            all_datas.append(rp)\n",
    "            \n",
    "print(len(all_datas))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>target</th>\n",
       "      <th>third_id</th>\n",
       "      <th>orderid</th>\n",
       "      <th>entry</th>\n",
       "      <th>order_invoice_type</th>\n",
       "      <th>stock</th>\n",
       "      <th>order_type</th>\n",
       "      <th>order_state</th>\n",
       "      <th>oi_orderType</th>\n",
       "      <th>oi_idShipmentType</th>\n",
       "      <th>...</th>\n",
       "      <th>rcin_summaryPredictResults_企业用户</th>\n",
       "      <th>rcin_summaryPredictResults_微信订单查询</th>\n",
       "      <th>rcin_summaryPredictResults_电子书</th>\n",
       "      <th>rcin_summaryPredictResults_无法加入购物车</th>\n",
       "      <th>rcin_summaryPredictResults_加盟快递</th>\n",
       "      <th>rcin_summaryPredictResults_商品好评率</th>\n",
       "      <th>rcin_summaryPredictResults_参加夺宝岛</th>\n",
       "      <th>rcin_summaryPredictResults_网银钱包提现异常</th>\n",
       "      <th>rcin_summaryPredictResults_补差价</th>\n",
       "      <th>candicate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 1100 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   target  third_id  orderid  entry  order_invoice_type  stock  order_type  \\\n",
       "0       0       0.0      1.0    3.0                 2.0    0.0        13.0   \n",
       "1       0       0.0      1.0    3.0                 2.0    0.0        13.0   \n",
       "2       0       0.0      1.0    3.0                 2.0    0.0        13.0   \n",
       "3       0       0.0      1.0    3.0                 2.0    0.0        13.0   \n",
       "4       0       0.0      1.0    3.0                 2.0    0.0        13.0   \n",
       "\n",
       "   order_state  oi_orderType  oi_idShipmentType  ...  \\\n",
       "0          2.0          15.0               70.0  ...   \n",
       "1          2.0          15.0               70.0  ...   \n",
       "2          2.0          15.0               70.0  ...   \n",
       "3          2.0          15.0               70.0  ...   \n",
       "4          2.0          15.0               70.0  ...   \n",
       "\n",
       "   rcin_summaryPredictResults_企业用户  rcin_summaryPredictResults_微信订单查询  \\\n",
       "0                              0.0                                0.0   \n",
       "1                              0.0                                0.0   \n",
       "2                              0.0                                0.0   \n",
       "3                              0.0                                0.0   \n",
       "4                              0.0                                0.0   \n",
       "\n",
       "   rcin_summaryPredictResults_电子书  rcin_summaryPredictResults_无法加入购物车  \\\n",
       "0                             0.0                                 0.0   \n",
       "1                             0.0                                 0.0   \n",
       "2                             0.0                                 0.0   \n",
       "3                             0.0                                 0.0   \n",
       "4                             0.0                                 0.0   \n",
       "\n",
       "   rcin_summaryPredictResults_加盟快递  rcin_summaryPredictResults_商品好评率  \\\n",
       "0                              0.0                               0.0   \n",
       "1                              0.0                               0.0   \n",
       "2                              0.0                               0.0   \n",
       "3                              0.0                               0.0   \n",
       "4                              0.0                               0.0   \n",
       "\n",
       "   rcin_summaryPredictResults_参加夺宝岛  rcin_summaryPredictResults_网银钱包提现异常  \\\n",
       "0                               0.0                                  0.0   \n",
       "1                               0.0                                  0.0   \n",
       "2                               0.0                                  0.0   \n",
       "3                               0.0                                  0.0   \n",
       "4                               0.0                                  0.0   \n",
       "\n",
       "   rcin_summaryPredictResults_补差价  candicate  \n",
       "0                             0.0          1  \n",
       "1                             0.0          2  \n",
       "2                             0.0          3  \n",
       "3                             0.0          4  \n",
       "4                             0.0          5  \n",
       "\n",
       "[5 rows x 1100 columns]"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "repeat_pd.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.concat?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "tmp_repeat.loc?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    0   1   2   3   4\n",
      "0   0   1   2   3   4\n",
      "1   5   6   7   8   9\n",
      "2  10  11  12  13  14\n",
      "3  15  16  17  18  19\n",
      "4  20  21  22  23  24\n",
      "    0   1   2   3   4\n",
      "0   0   1   2   3   4\n",
      "0   0   1   2   3   4\n",
      "0   0   1   2   3   4\n",
      "0   0   1   2   3   4\n",
      "0   0   1   2   3   4\n",
      "1   5   6   7   8   9\n",
      "1   5   6   7   8   9\n",
      "1   5   6   7   8   9\n",
      "1   5   6   7   8   9\n",
      "1   5   6   7   8   9\n",
      "2  10  11  12  13  14\n",
      "2  10  11  12  13  14\n",
      "2  10  11  12  13  14\n",
      "2  10  11  12  13  14\n",
      "2  10  11  12  13  14\n",
      "3  15  16  17  18  19\n",
      "3  15  16  17  18  19\n",
      "3  15  16  17  18  19\n",
      "3  15  16  17  18  19\n",
      "3  15  16  17  18  19\n",
      "4  20  21  22  23  24\n",
      "4  20  21  22  23  24\n",
      "4  20  21  22  23  24\n",
      "4  20  21  22  23  24\n",
      "4  20  21  22  23  24\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "pd1=pd.DataFrame(np.arange(25).reshape(5,5))\n",
    "pd2=pd.DataFrame()\n",
    "print(pd1)\n",
    "for i in range(len(pd1)):\n",
    "    a=pd1.loc[i]\n",
    "    d=pd.DataFrame(a).T\n",
    "    pd2=pd2.append([d]*5)  #每行复制5倍\n",
    "print(pd2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "302.8px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
